package com.heima.feigns.fallback;
import com.heima.feigns.WemediaFeign;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.wemedia.pojos.WmNews;
import com.heima.model.wemedia.pojos.WmUser;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@Component
@Slf4j
public class WemediaFeignFallback implements FallbackFactory<WemediaFeign> {

    @Override
    public WemediaFeign create(Throwable throwable) {
        throwable.printStackTrace();
        return new WemediaFeign() {
            @Override
            public ResponseResult<WmUser> findByName(String name) {
                log.error("远程调用自媒体服务findByName出错==>{}  参数==>",throwable.getCause(),name);
                //打印错误日志 提示用户
                return ResponseResult.errorResult(AppHttpCodeEnum.REMOTE_SERVER_ERROR);
            }

            @Override
            public ResponseResult<WmUser> save(WmUser wmUser) {
                log.error("远程调用自媒体服务findByName出错==>{}  参数==>",throwable.getCause(),wmUser);
                return ResponseResult.errorResult(AppHttpCodeEnum.REMOTE_SERVER_ERROR);
            }

            @Override
            public ResponseResult<WmNews> findWmNewsById(Integer id) {
                return null;
            }

            @Override
            public ResponseResult updateWmNews(WmNews wmNews) {
                return null;
            }


        };
    }
}
